/* 
 * Advanced Foundation Classes
 * Copyright (C) 2000/2004  Fabio Rotondo - Andrea Galimberti
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *  
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *  
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
#ifndef AFC_PYCONNECTOR
#define AFC_PYCONNECTOR

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>

/* The following include is indepentend of the actual Python version installed
   on the system. The actual version will be specified when invoking the gcc
   compiler by means of the -I option. */
#include <Python.h>

#include "../afc.h"

/* AFC afc_pyconnector Magic Number */
#define AFC_PYCONNECTOR_MAGIC ( 'P' << 24 | 'Y' << 16 | 'C' << 8 | 'O' )

/* AFC afc_pyconnector Base value for constants */
#define AFC_PYCONNECTOR_BASE 0x11000


/* Errors for afc_pyconnector */

#define AFC_PYCONNECTOR_ERR_NO_ERROR          0                       /* No error occurred                       */
#define AFC_PYCONNECTOR_ERR_NO_MEMORY         AFC_PYCONNECTOR_BASE + 1  /* No memory for required operation        */
#define AFC_PYCONNECTOR_ERR_NULL_POINTER      AFC_PYCONNECTOR_BASE + 2  /* Null pointer passed as argument         */
#define AFC_PYCONNECTOR_ERR_INVALID_POINTER   AFC_PYCONNECTOR_BASE + 3  /* Pointer passed is not of the right kind */
#define AFC_PYCONNECTOR_ERR_CLASS_UNKNOWN     AFC_PYCONNECTOR_BASE + 4  /* DynamicClass not loaded */
#define AFC_PYCONNECTOR_ERR_METHOD_UNKNOWN    AFC_PYCONNECTOR_BASE + 5  /* DynamicClass method not defined */
#define AFC_PYCONNECTOR_ERR_TYPE_ERROR				AFC_PYCONNECTOR_BASE + 6  /* Wrong argument type */


#define AFC_PYCONNECTOR_BUFFER_SIZE			256 		/* size of the temporary buffer used for sprintf */

#define AFC_PYCONNECTOR_PLUGIN_ATTRIBUTE_NAME_SIZE   128  /* size of the PyConnectorPlugin->attribute_requested string */

#define AFC_PYCONNECTOR_DELETE_KEEP    0   /* the PyConnector object should be kept intact upon exiting */
#define AFC_PYCONNECTOR_DELETE_DELETE  1   /* the PyConnector object should be deleted upon exiting */


struct afc_pyconnector {
	unsigned long magic;
	AFC * afc;
	DynamicClassMaster * dynmast;
	Dictionary * plugins;
	Dictionary * pytypes;
	Dictionary * pymethods;

	char * buffer;

	PyObject * pymodule;
	PyObject * base_exception;

	int delete_mode;
	ArrayMaster * tempobjects;
};

typedef struct afc_pyconnector PyConnector;


struct afc_pyconnector_plugin {
	PyObject_HEAD
	char * class_name;
	DynamicClass * dclass;
	char * attribute_requested;
	PyConnector * parent;
};

typedef struct afc_pyconnector_plugin PyConnectorPlugin;


struct afc_pyconnector_object {
	PyObject_HEAD
	PyTypeObject * pycon_obj_type;
	PyConnector * pycon;
};

typedef struct afc_pyconnector_object PyConnectorObject;


/* functions */

PyConnector * afc_pyconnector_new ( void );
int afc_pyconnector_delete ( PyConnector * );
int afc_pyconnector_clear ( PyConnector * );
int afc_pyconnector_init ( PyConnector *, DynamicClassMaster *, char * );

int afc_pyconnector_add_commands ( PyConnector *, DynamicClassMaster * );
int afc_pyconnector_tuple_to_array_master ( PyConnector *, PyObject *, ArrayMaster *, int, char * );
PyObject * afc_pyconnector_value_to_pyobject ( PyConnector *, int, void * );
int afc_pyconnector_execute ( PyConnector *, DynamicClass *, char *, PyObject *, int );
int afc_pyconnector_objects_delete_recursive ( void *, int );
void * afc_pyconnector_pyobject_to_value ( PyConnector *, PyObject * );

#endif
